package com.neusoft.exercise;
import java.util.Scanner;
import java.io.*;
/**
 * 
 * @author LYW
 *
 *已知a,b均是整型变量，写出将a,b两个变量中的值互换的程序。
 *
 */
public class InterChange {

	public static void main(String[] args) {
		// 1. 定义中间变量，进行互换
		int ia = 15;
		int ib = 23;
		int ic = 0;
		System.out.println("交换之前ia ib分别为" + ia +" "+ ib);
		ic = ib;
		ib = ia;
		ia = ic;
		System.out.println("交换之后ia ib分别为" + ia +" " + ib);
		
		//2.用异或^
		System.out.println("交换之前ia ib分别为" + ia +" "+ ib);
		ia = ia ^ ib;
		ib = ia ^ ib;
		ia = ia ^ ib;
		System.out.println("交换之后ia ib分别为" + ia +" " + ib);
		
		//3.相加在相减
		System.out.println("交换之前ia ib分别为" + ia +" "+ ib);
		ia = ia + ib;
		ib = ia - ib;
		ia = ia - ib;
		System.out.println("交换之后ia ib分别为" + ia +" " + ib);
		
		//4.
	}

}
